package m.jclecai.com.adapter.holder;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import m.jclecai.com.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import m.jclecai.com.adapter.PayRedpacketAdapter;
import m.jclecai.com.bean.RedPacketBean;
import m.jclecai.com.utils.DateUtil;
import m.jclecai.com.utils.StringUtils;

/**
 * Created by ZD on 2017/5/11.
 */

public class PayRedpacketHolder extends RecyclerView.ViewHolder {

    @BindView(R.id.iv_pkg)
    public ImageView ivPkg;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_money)
    TextView tv_money;
    @BindView(R.id.llBg)
    LinearLayout llBg;
    Context context;

    public PayRedpacketHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this,itemView);
    }

    public void init(RedPacketBean bean,PayRedpacketAdapter.FROM from){
        ivPkg.setImageResource(bean.isCheck() ? R.drawable.redbg2 : R.drawable.redbg1);
        tvTitle.setText(bean.getTitle());
        tvTime.setText("截止时间:"+DateUtil.formatDate(bean.getEndtime(),"yyyy-MM-dd"));
        tv_money.setText(StringUtils.decimalFormat(bean.getRestmoney())+"元");
        switch (from){
            case BuyRedPkgFragment:
                llBg.setBackgroundColor(ContextCompat.getColor(itemView.getContext(),R.color.white));
                tv_money.setText(StringUtils.decimalFormat(bean.getAllmoney())+"元");
                tvTime.setText(Html.fromHtml(String.format(itemView.getContext().getResources().
                        getString(R.string.buy_pkg),bean.getBuymoney())));
                break;
            case LotteryPayActivity:
                break;
        }
    }
}
